package com.platform.common.bean;

import com.platform.common.menus.ResultCodeEnum;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;

/**
 * describe:REST风格统一返回的Bean对象
 * @author rainly
 * @date 2019/11/29
 * @time 9:34 上午
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
public class Result implements Serializable {
    private static final long serialVersionUID = -4577255781088498763L;

    private Integer code;

    private String message;

    private Object data;

    public Result(ResultCodeEnum resultCode){
        this.code = resultCode.getCode();
        this.message = resultCode.getMessage();
        this.data = "";
    }

    public Result(ResultCodeEnum resultCode, Object data){
        this.code = resultCode.getCode();
        this.message = resultCode.getMessage();
        this.data = data;
    }

    public static Result success(){
        return new Result(ResultCodeEnum.SUCCESS);
    }

    public static Result success(Object data){
        return new Result(ResultCodeEnum.SUCCESS,data);
    }

    public static Result failure(){
        return new Result(ResultCodeEnum.FAILURE);
    }

    public static Result failure(Object data){
        return new Result(ResultCodeEnum.FAILURE,data);
    }

    public static Result failure(ResultCodeEnum codeEnum){
        return new Result(codeEnum);
    }

    public static Result failure(ResultCodeEnum codeEnum,Object data){
        return new Result(codeEnum,data);
    }

    public static Result failure(Integer code,String message){
        return new Result(code, message, null);
    }
}
